package io.yizoo.business.controller;

import io.yizoo.business.entity.biz_cms_news;
import io.elm.core.CoreController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/cms/news")
public class cms_newsController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_cms_news.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_cms_news.class)
                        .IsWhere("and title like concat('%', #{title}, '%')", "title")
                        .IsWhere("and author like concat('%', #{author}, '%')", "author")
                        .IsWhere("and type=#{type}","type")
                        .OrderBy("publish_time desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }
}
